<?php
	include "../../connect.php";
	if (isset($_REQUEST["Update"]))
	{
	$sanid= $_REQUEST["sanid"];
	$tieude=$_REQUEST["tieude"];
	$curPage=$_REQUEST['curPage'];
	$mota = stripslashes($_POST['mota']);
	$hinhold="../../images/san/".$_REQUEST["hinhold"];
	$hinhnew=$_FILES["hinh"];
	$type=$hinhnew["type"];
	$arr = array("image/jpeg", "image/gif","image/jpg","image/png");
	if(in_array($type, $arr)>0)
	{
		$imageInfo = explode('.', $hinhnew["name"]);  //cắt chuỗi ở những nơi có dấu .		
		$filename = $sanid.".".$imageInfo[1]; 
		$path= "../../images/san/$filename";
		$temp= $hinhnew["tmp_name"];
		move_uploaded_file($temp, $path);
		$sql= "update san set  mota='$mota',tieude='$tieude',hinh='$filename' where sanid='$sanid' ";
		unlink($hinhold);
	}
	else
		$sql= "update san set  mota='$mota',tieude='$tieude' where sanid='$sanid' ";
	$kq=mysql_query($sql);
	if(!$kq)
	{
		$val='Cập nhật không thành công';
		echo "<script>
				window.location='../index.php?actionadmin=Sân&key=1&val=$val&curPage=$curPage'</script>";
	}
	else{				
			 $val='Cập nhật thành công';
			 echo "<script>
			 		window.location='../index.php?actionadmin=Sân&key=2&val=$val&curPage=$curPage';</script>"; 	
		}	
	}
?>
